AC_DEFUN_ONCE([LC_CHECK_GNU_ATOMIC_BUILTINS],
[ AC_PREREQ([2.59])
  AC_CHECK_HEADERS([ext/atomicity.h bits/atomicity.h])
  AS_VAR_PUSHDEF([CACHEVAR], [lc_cv_[]_AC_LANG_ABBREV[]_atomic_builtins])
  AC_CACHE_CHECK([_AC_LANG[] compiler for atomic builtins], [CACHEVAR], dnl
    [AS_IF([test x"${ac_cv_header_ext_atomicity_h}" != x], [_lc_include='ext/atomicity.h'],
      [test x"${ac_cv_header_bits_atomicity_h}" != x], [_lc_include='bits/atomicity.h'])
     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <${_lc_include}>], dnl
      [_Atomic_word x=0;return __gnu_cxx::__exchange_and_add(&x, 1);])], dnl
      [AS_VAR_SET([CACHEVAR], [yes])], [AS_VAR_SET([CACHEVAR], [no])])])
  AS_IF([test x"${CACHEVAR}" = xyes],
    [AC_DEFINE([HAVE___EXCHANGE_AND_ADD], [1], [define if compiler supports atomic builtins])
     AC_DEFINE([HAVE__ATOMIC_WORD], [1], [define if compiler supports _Atomic_word])],
    [m4_default($1,:)])
  AS_VAR_POPDEF([CACHEVAR])
])
